package com.robam.cloud.common.bean.restful.entity;

import lombok.Data;

/**
 * 基本异常
 */
@Data
public class ServiceException extends RuntimeException {

    private static final long serialVersionUID = -3804636984105926826L;
    protected String msg;
    private Throwable cause;
    private int code;
    private String traceId;

    @Override
    public Throwable getCause() {
        return this.cause == this ? null : this.cause;
    }

    @Override
    public String getMessage() {
        return super.getMessage();
    }

    public ServiceException(int code, String msg, Exception e) {
        super(msg);
        this.code = code;
        this.cause = e;
        this.traceId = null;
    }

    public ServiceException(int code, String msg) {
        super(msg);
        this.msg = msg;
        this.code = code;
        this.cause = null;
        this.traceId = null;
    }

    public ServiceException(String msg) {
        super(msg);
        this.msg = msg;
        this.code = RespMsg.RESULT_CODE_500;
        this.cause = null;
        this.traceId = null;
    }

    public ServiceException(String msg, Exception e) {
        super(msg);
        this.msg = msg;
        this.code = RespMsg.RESULT_CODE_500;
        this.cause = e;
        this.traceId = null;
    }
}
